﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Drawing;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using UofCASE.AgileProductLinerDSL;
using Microsoft.VisualStudio.Modeling.Diagrams;
using Microsoft.VisualStudio.Modeling;

namespace APLDTests {
    [TestClass]
    public class TestShapeColoringTest {
        [TestMethod]
        public void TestTestShapeBackgoundColoring() {
            ModelHelper model = ModelHelper.GetModel(true);
            TestShape testShape = model.GetElement<TestShape>("testShape");
            Test test = testShape.ModelElement as Test;
            Assert.AreEqual(TestColor.Unmapped, GetBackgroundColor(testShape));

            using (Transaction t = model.Store.TransactionManager.BeginTransaction("Map test")) {
                test.IsMapped = true;
                t.Commit();
            }
            Assert.AreEqual(TestColor.NoTestResult, GetBackgroundColor(testShape));

            using (Transaction t = model.Store.TransactionManager.BeginTransaction("Map test")) {
                test.LastTestRun = TestResult.Exception;
                t.Commit();
            }
            Assert.AreEqual(TestColor.Fail, GetBackgroundColor(testShape));

            using (Transaction t = model.Store.TransactionManager.BeginTransaction("Map test")) {
                test.LastTestRun = TestResult.Ignored;
                t.Commit();
            }
            Assert.AreEqual(TestColor.Fail, GetBackgroundColor(testShape));

            using (Transaction t = model.Store.TransactionManager.BeginTransaction("Map test")) {
                test.LastTestRun = TestResult.Fail;
                t.Commit();
            }
            Assert.AreEqual(TestColor.Fail, GetBackgroundColor(testShape));

            using (Transaction t = model.Store.TransactionManager.BeginTransaction("Map test")) {
                test.LastTestRun = TestResult.Successful;
                t.Commit();
            }
            Assert.AreEqual(TestColor.Success, GetBackgroundColor(testShape));
        }


        [TestMethod]
        public void TestSetBackgroundColor() {
            ModelHelper model = ModelHelper.GetModel(true);
            TestShape testShape = model.GetElement<TestShape>("testShape");
            
            Assert.AreEqual(TestColor.Unmapped, GetBackgroundColor(testShape));

            testShape.SetBackgroundColor(KnownColor.CornflowerBlue);
            Assert.AreEqual(KnownColor.CornflowerBlue, GetBackgroundColor(testShape));
        }
        
        private KnownColor GetBackgroundColor(TestShape testShape) {
            return testShape.StyleSet.GetOverriddenBrushSettings(DiagramBrushes.ShapeBackground).Color.ToKnownColor();
        }
    }
}
